﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.System.Db;
using Shpm.App.Master.Bean;
using System.Collections;
using Shpm.App.Input.Bean;

/// <summary>
/// Summary description for BookFoodDao
/// </summary>
namespace Shpm.App.Input.Dao
{
    public class BookFoodDao : ShpmBaseDao
    {
        public const string FIND_MEMBER_DINNER_DETAIL = "BookFood.ListMemberDinnerDetails";
        public const string FIND_MEMBER_DINNERS = "BookFood.ListMemberDinners";
        public const string GET_MEMBER_DINNER = "BookFood.LoadMemberDinner";
        public const string FIND_DISH   = "BookFood.ListDish";
        public const string GET_DISH    = "BookFood.LoadDish";
        public const string GET_MEMBER_DINNER_DETAIL = "BookFood.LoadMemberDinnerDetail";
        public const string FIND_FOOD_INFO = "BookFood.ListFoodInfo";
        public const string INS_MEMBER_DINNER = "BookFood.InsMemberDinner";
        public const string INS_MEMBER_DINNER_DETAIL = "BookFood.InsMemberDinnerDetail";

        public const string UPD_MEMBER_DINNER = "BookFood.UpdMemberDinner";
        public const string DEL_MEMBER_DINNER_DETAIL = "BookFood.DelMemberDinnerDetail";
        //20080110 HUANGXIN ADD
        public const string LIST_DINNER_SEND_DETAIL = "BookFood.ListDinnerSendDetail";
        public const string LIST_DINNER_SEND_TOTAL = "BookFood.ListDinnerSendTotal";
        //ADD END
        public BookFoodDao()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public IList FindMemberDinnerDetail(MemberDinnerDetailBean paramBean)
        {
            return base.QueryForList(FIND_MEMBER_DINNER_DETAIL, paramBean);
        }

        public IList FindMemberDinners(MemberDinnerBean paramBean)
        {
            return base.QueryForList(FIND_MEMBER_DINNERS, paramBean);
        }
        public MemberDinnerBean GetMemberDinner(MemberDinnerBean paramBean)
        {
            return (MemberDinnerBean)base.QueryForObject(GET_MEMBER_DINNER, paramBean);
        }
        public IList FindDish(DishBean paramBean)
        {
            return base.QueryForList(FIND_DISH, paramBean);
        }
        //public DishBean GetDish(DishBean paramBean)
        //{
        //    return (DishBean)base.QueryForObject(GET_DISH, paramBean);
        //}
        public MemberDinnerDetailBean GetMemberDinnerDetail(MemberDinnerDetailBean paramBean)
        {
            return (MemberDinnerDetailBean)base.QueryForObject(GET_MEMBER_DINNER_DETAIL, paramBean);
        }
        public IList FindFoodInfo(DishBean paramBean)
        {
            return base.QueryForList(FIND_FOOD_INFO, paramBean);
        }
        public object InsMemberDinner(MemberDinnerBean paramBean)
        {
            return base.Insert(INS_MEMBER_DINNER, paramBean);
        }
        public object InsMemberDinnerDetail(MemberDinnerDetailBean paramBean)
        {
            return base.Insert(INS_MEMBER_DINNER_DETAIL, paramBean);
        }
        public int UpdMemberDinner(MemberDinnerBean paramBean)
        {
            return base.Update(UPD_MEMBER_DINNER, paramBean);
        }
        public int DelMemberDinnerDetail(MemberDinnerDetailBean paramBean)
        {
            return base.Delete(DEL_MEMBER_DINNER_DETAIL, paramBean);
        }
        //20080110 HUANGXIN ADD
        public IList ListDinnerSendDetail(DinnerSendBean paramBean)
        {
            return base.QueryForList(LIST_DINNER_SEND_DETAIL, paramBean);
        }
        public IList ListDinnerSendTotal(DinnerSendBean paramBean)
        {
            return base.QueryForList(LIST_DINNER_SEND_TOTAL, paramBean);
        }
        //ADD END
        public int Insert(IList list, MemberDinnerBean memberDinnerBean)
        {
            try 
            {
                base.BeginTransaction();
                //会员订餐信息
                int dinnerId = (int)InsMemberDinner(memberDinnerBean);

                //会员订餐信息_详细
                MemberDinnerDetailBean bean = new MemberDinnerDetailBean();
                for (int i = 0; i < list.Count; i++)
                {
                    bean = (MemberDinnerDetailBean)list[i];
                    bean.DinnerId = dinnerId;
                    //bean.DishId = paramBean.DishId;
                    //bean.DishPrice = paramBean.DishPrice;
                    //bean.DishQuantity = paramBean.DishQuantity;
                    bean.UserId = memberDinnerBean.UserId;
                    InsMemberDinnerDetail(bean);
                }
                base.CommitTransaction();
                return dinnerId;
            }
            catch (Exception e)
            {
                //log.Fatal(e);
                base.RollBackTransaction();
                throw new DataAccessException(e);
            }
        }

        public void Upd(IList list, MemberDinnerBean paramBean)
        {
             try 
            {
                base.BeginTransaction();
                UpdMemberDinner(paramBean);
                MemberDinnerDetailBean bean = new MemberDinnerDetailBean();
                bean.DinnerId = paramBean.DinnerId;
                DelMemberDinnerDetail(bean);

                for (int i = 0; i < list.Count; i++)
                {
                    bean = (MemberDinnerDetailBean)list[i];
                    bean.DinnerId = paramBean.DinnerId;
                    bean.UserId = paramBean.UserId;
                    InsMemberDinnerDetail(bean);
                }

                base.CommitTransaction();
            }
            catch (Exception e)
            {
                //log.Fatal(e);
                base.RollBackTransaction();
                throw new DataAccessException(e);
            }
        }
    }
}